package lesson03;

import org.w3c.dom.css.Counter;

public class Demo_303 {
    public static void main(String[] args) throws InterruptedException {
        //Java程序的入口点，也就是程序开始执行的地方，
        // throws InterruptedException表示可能抛出InterruptedException异常

        //初始化累加对象
        Counter303 counter = new Counter303();

        //创建两个线程对一个变量进时累加
        Thread t1 = new Thread(()->{
            //5万次
            for (int i=0;i<50000;i++){
                counter.increase();
            }

        });
        Thread t2 = new Thread(()-> {
            //5万次
            for (int i = 0; i < 50000; i++) {
                counter.increase();
            }
        });
        //启动线程
        t1.start();
        t2.start();

        //等待线程执行完成
        t1.join();
        t2.join();

        //查看运行结果
        System.out.println("count ="+counter.count);
    }
}

class Counter303{
    //初始值是0
    public int count = 0;

    //累加方法

    public void increase(){
        count++;
    }
}